/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on Apr 9, 2010, 9:44:15 PM
 */
package com.lps.client.view;

import com.lps.client.Client;
import com.lps.client.controller.MainFeatureController;
import com.lps.model.User;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author DoHongPhuc
 * Description
 * VN:
 * -MainFrame chứa các Panel của chương trình
 * -Cần kiểm tra được Type User Login để load component
 */
public class MainFrame extends javax.swing.JFrame {

    MainFeatureController featureController;

    public MainFrame() {
        initComponents();
        this.setLocationRelativeTo(null);
        featureController = new MainFeatureController(pnMain, mnAccount,
                mnAdmin, mnCallCenter, mnDispatch, mnOrder, mnTechnical);
        featureController.initFeatures();
        initFeatures();
    }

    /**
     *
     * @return
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnMain = new javax.swing.JPanel();
        panelBottom = new javax.swing.JPanel();
        lblUserName = new javax.swing.JLabel();
        lblSystemName = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        changePasswordMenuItem = new javax.swing.JMenuItem();
        logoutMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        exitMennuItem = new javax.swing.JMenuItem();
        mnAccount = new javax.swing.JMenu();
        mnCallCenter = new javax.swing.JMenu();
        mnOrder = new javax.swing.JMenu();
        mnDispatch = new javax.swing.JMenu();
        mnTechnical = new javax.swing.JMenu();
        mnAdmin = new javax.swing.JMenu();
        helpMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Bug Reporting System");

        pnMain.setBackground(new java.awt.Color(153, 153, 153));
        pnMain.setLayout(new java.awt.BorderLayout());

        lblUserName.setText("lblUserName");

        lblSystemName.setText("lblSystemName");

        javax.swing.GroupLayout panelBottomLayout = new javax.swing.GroupLayout(panelBottom);
        panelBottom.setLayout(panelBottomLayout);
        panelBottomLayout.setHorizontalGroup(
            panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBottomLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblUserName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 744, Short.MAX_VALUE)
                .addComponent(lblSystemName)
                .addContainerGap())
        );
        panelBottomLayout.setVerticalGroup(
            panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBottomLayout.createSequentialGroup()
                .addGroup(panelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSystemName)
                    .addComponent(lblUserName))
                .addContainerGap(6, Short.MAX_VALUE))
        );

        fileMenu.setMnemonic('F');
        fileMenu.setText("File");

        changePasswordMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/brs/client/images/change pass.png"))); // NOI18N
        changePasswordMenuItem.setText("Change Password");
        fileMenu.add(changePasswordMenuItem);

        logoutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/brs/client/images/logout.png"))); // NOI18N
        logoutMenuItem.setText("Logout");
        fileMenu.add(logoutMenuItem);
        fileMenu.add(jSeparator1);

        exitMennuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/brs/client/images/exit.png"))); // NOI18N
        exitMennuItem.setText("Exit");
        fileMenu.add(exitMennuItem);

        jMenuBar1.add(fileMenu);

        mnAccount.setText("Account");
        mnAccount.setEnabled(false);
        jMenuBar1.add(mnAccount);

        mnCallCenter.setText("Call Center");
        mnCallCenter.setEnabled(false);
        jMenuBar1.add(mnCallCenter);

        mnOrder.setText("Order");
        mnOrder.setEnabled(false);
        jMenuBar1.add(mnOrder);

        mnDispatch.setText("Dispatch");
        mnDispatch.setEnabled(false);
        jMenuBar1.add(mnDispatch);

        mnTechnical.setText("Technician");
        mnTechnical.setEnabled(false);
        jMenuBar1.add(mnTechnical);

        mnAdmin.setText("Administrator");
        mnAdmin.setEnabled(false);
        jMenuBar1.add(mnAdmin);

        helpMenu.setText("Help");
        helpMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                helpMenuMouseClicked(evt);
            }
        });
        jMenuBar1.add(helpMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnMain, javax.swing.GroupLayout.DEFAULT_SIZE, 895, Short.MAX_VALUE)
            .addComponent(panelBottom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(pnMain, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBottom, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void helpMenuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_helpMenuMouseClicked
        JOptionPane.showMessageDialog(pnMain, "Please open the \"help.pdf\" file");
    }//GEN-LAST:event_helpMenuMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem changePasswordMenuItem;
    private javax.swing.JMenuItem exitMennuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JLabel lblSystemName;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JMenuItem logoutMenuItem;
    private javax.swing.JMenu mnAccount;
    private javax.swing.JMenu mnAdmin;
    private javax.swing.JMenu mnCallCenter;
    private javax.swing.JMenu mnDispatch;
    private javax.swing.JMenu mnOrder;
    private javax.swing.JMenu mnTechnical;
    private javax.swing.JPanel panelBottom;
    private javax.swing.JPanel pnMain;
    // End of variables declaration//GEN-END:variables

    /**
     * Add ActionListener for MenuItem
     */
    private void initFeatures() {
        /**
         * Change Password for current user
         */
        changePasswordMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ChangePasswordDialog dialog = new ChangePasswordDialog(null, true);
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
            }
        });

        /**
         * Logout current user
         * Create new Login
         */
        logoutMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                dispose();
                LoginFrame newlogin = new LoginFrame();
                newlogin.setVisible(true);
            }
        });
        /**
         * Exit System
         */
        exitMennuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        User currentUser = Client.getInstance().getCurrentUser();
        lblUserName.setText("User Login : " + currentUser.getUserName());
        lblSystemName.setText("Bug Reporting System");
    }
}
